/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "StateSystem.h"
#include "WorldManager.h"

namespace PQGame
{
	StateSystem::StateSystem(void)
	{
	}

	StateSystem::~StateSystem(void)
	{
	}

	StateSystem &StateSystem::getSingleton()
	{
		static StateSystem sys;
		return sys;
	}

	void StateSystem::init(PQEngine::SceneObject* sceneObject)
	{
		WorldManager::getSingleton().init(sceneObject);
		enterState(CREATE_CHARACTER);//enter sinbad
	}

	void StateSystem::enterState(StateType type)
	{
		currentState=type;
		switch(type){
		case START_SYSTEM:
		case LOGIN:
		case REGIST:
		case CHOOSE_AVATAR:
		case CHOOSE_HOME_WORLD:
		case ENTER_HOME_WORLD:
		case ENTER_WORLD:
		case LIVE_IN_WORLD:
		case EXIT_WORLD:	
		case EXIT_APPLICATION:
		case CREATE_CHARACTER:
			WorldManager::getSingleton().enterWorld(MAIN_WORLD);
			currentState=LIVE_IN_WORLD;
			break;
		}
	}
	
	//update the logic
	void StateSystem::update(float deltaT)
	{
		switch(currentState){
		case START_SYSTEM:
		case LOGIN:
		case REGIST:
		case CHOOSE_AVATAR:
		case CHOOSE_HOME_WORLD:
		case ENTER_WORLD:
		case EXIT_WORLD:	
		case EXIT_APPLICATION:
		case LIVE_IN_WORLD:
			WorldManager::getSingleton().update(deltaT);
			break;
		}
	}

}
